/**
 * ===========================================================================
 * 版权所有 湖南免了么网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.mianle.me
 * ===========================================================================
 * 11:10 2018/6/19
 */
package com.mianle.userapi;

import com.mianle.userapi.service.RedisGeo;
import com.mianle.userapi.service.TestException;
import com.mianle.userapi.service.async.Task;
import com.mianle.userapi.util.LbsUtil;
import com.mianle.userapi.util.SearchGeo;
import lombok.SneakyThrows;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @Author: yiyuan
 * @Description:
 * @Date: Created in 11:10 2018/6/19
 *
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class FileTest {

//    @Value("${web.upload-path}")
//    private String path;


    @Autowired
    private RedisGeo redisGeo;

    @Autowired
    private Task task;

    @Autowired
    private TestException testException;

    @Test
    public void test1() {
        int r =testException.test1();
        System.out.println("----------result--"+ r);
    }

    @Test
    public void test2(){
        int r =testException.test2();
        System.out.println("----------result--"+ r);
    }

    @Test
    public void test3(){
        int r =testException.test3();
        System.out.println("----------result------------------"+ r);
    }

    @Test
    public void test4(){
        testException.test4();
    }

    @Test
    public void test5() {

        List<GeoLocation<String>> ite = Lists.newArrayList();

        GeoLocation<String> geo1 = new GeoLocation<String>("黄花机场sd", new Point(28.1887,113.226255));
        ite.add(geo1);
        GeoLocation<String> geo2 = new GeoLocation<String>("长沙生态动物园", new Point(28.033517,113.002907));
        ite.add(geo2);
        GeoLocation<String> geo3 = new GeoLocation<String>("湖南省政府", new Point(28.116367,112.98248));
        ite.add(geo3);
        GeoLocation<String> geo4 = new GeoLocation<String>("长沙市中心医院", new Point(28.142557,112.997758));
        ite.add(geo4);
        GeoLocation<String> geo5 = new GeoLocation<String>("中电软件园总部", new Point(28.230011,112.882562));
        ite.add(geo5);
        GeoLocation<String> geo6 = new GeoLocation<String>("园区公租房", new Point(28.23038,112.880137));
        ite.add(geo6);
        GeoLocation<String> geo7 = new GeoLocation<String>("德元大包", new Point(28.229529,112.878319));
        ite.add(geo7);
        GeoLocation<String> geo8 = new GeoLocation<String>("园区餐厅", new Point(28.229269,112.876098));
        ite.add(geo8);
        GeoLocation<String> geo9 = new GeoLocation<String>("安智教育", new Point(28.229723,112.874784 ));
        ite.add(geo9);
        GeoLocation<String> geo10 = new GeoLocation<String>("吃喝玩乐别墅轰趴", new Point(28.197096,112.902775 ));
        ite.add(geo10);
        GeoLocation<String> geo11 = new GeoLocation<String>("纤云美丽生活馆", new Point(28.195186,112.89975  ));
        ite.add(geo11);
        GeoLocation<String> geo12 = new GeoLocation<String>("食流疯概念餐厅", new Point(28.142268,112.937365));
        ite.add(geo12);
        GeoLocation<String> geo13 = new GeoLocation<String>("凯德广场", new Point(28.154072,112.995358 ));
        ite.add(geo13);
        GeoLocation<String> geo14 = new GeoLocation<String>("瑞祥客房", new Point(28.150628,112.99538 ));
        ite.add(geo14);
        GeoLocation<String> geo15 = new GeoLocation<String>("不怕辣烧鸡公", new Point(28.148689,112.999789 ));
        ite.add(geo15);
        GeoLocation<String> geo16 = new GeoLocation<String>("蒸湘坊", new Point(28.229385,112.878771 ));
        ite.add(geo16);
        GeoLocation<String> geo17 = new GeoLocation<String>("健怡缘中医经咯养生会所", new Point(28.225234,112.882694 ));
        ite.add(geo17);
        GeoLocation<String> geo18 = new GeoLocation<String>("沈婷食品店", new Point(28.225744,112.879808 ));
        ite.add(geo18);

        for (GeoLocation<String> location : ite) {
            String k = LbsUtil.geoHashEncode(location.getPoint().getY(), location.getPoint().getX(), 3);
            redisGeo.cacheGeo(k, location.getPoint().getX(), location.getPoint().getY(), location.getName(), 1000*60*10);
        }
    }

    @Test
    public void test6() {
        System.out.println("jrebel------------测试"+"ces");
        System.out.println("luyujiao");
        double lng = 112.881042;
        double lat = 28.228963;
        String hash = LbsUtil.geoHashEncode(lng, lat, 3);
        SearchGeo param = new SearchGeo(hash, lng, lat, 10D, RedisGeoCommands.DistanceUnit.KILOMETERS);
        System.out.println("-------------------------------------------------------------------------");
        System.out.println(redisGeo.radiusGeo(param).toString());
    }

    @Test
    public void test() throws Exception {
/*        long start = System.currentTimeMillis();
        Future<String> task1 = task.doTaskOne();
        Future<String> task2 = task.doTaskTwo();
        Future<String> task3 = task.doTaskThree();
        while(true) {
            if(task1.isDone() && task2.isDone() && task3.isDone()) {
                // 三个任务都调用完成，退出循环等待
                break;
            }
            Thread.sleep(1000);
        }
        long end = System.currentTimeMillis();
        System.out.println("任务全部完成，总耗时：" + (end - start) + "毫秒");*/
    }

    @Test
    @SneakyThrows
    public void test11() {
        for (int i = 0; i < 100000; i++) {
            task.doTaskOne();
            task.doTaskTwo();
            task.doTaskThree();
            if (i == 99999) {
                System.exit(0);
            }
        }
    }

    /** 文件上传测试 */
   /* @Test
    public void uploadTest() throws Exception {
        File f = new File("D:/tup.jpg");

        FileCopyUtils.copy(f, new File(path+"/tup.jpg"));
    }

    @Test
    public void listFilesTest() {
        File file = new File(path);
        for(File f : file.listFiles()) {
            System.out.println("fileName ---------------------------------------------------------: "+f.getName());
        }
    }*/
}
